package edu.uic.ids517.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import edu.uic.ids517.model.CreateTableBean;
import edu.uic.ids517.model.DatabaseAccessBean;

public class CreateTableServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
		
		System.out.println("CreateTableServlet");
		String nextUrl = "/dbAccess.jsp";	
		HttpSession session = request.getSession();
		
			
		/***   DB Access Bean  ****/
		DatabaseAccessBean dbase = (DatabaseAccessBean) session.getAttribute("dbaseBean");
		CreateTableBean createTable = (CreateTableBean) session.getAttribute("createTableBean");		
		createTable.setTableName(request.getParameter("tableName"));				
		createTable.setColumn1(request.getParameter("column1"));
		createTable.setDataType1(request.getParameter("dataType1"));
		createTable.setColumn2(request.getParameter("column2"));
		createTable.setDataType2(request.getParameter("dataType2"));
		createTable.setColumn3(request.getParameter("column3"));
		createTable.setDataType3(request.getParameter("dataType3"));
		
		
		
		dbase.setCreateBean(createTable);
		int result = dbase.executeCreateSQL();
		if(result != 0){
			System.out.println("SUCCESS: TABLE CRETATED");
		}
		
		RequestDispatcher dispatcher = request.getRequestDispatcher(nextUrl); 
		dispatcher.forward(request, response); 
		
		
}

}
